package bud.tools.maxnogen;

import java.util.Hashtable;
import java.util.Map;

import bud.util.StringUtils;

@SuppressWarnings("unchecked")
public class MaxnoMgr
{
    private static MaxnoMgr generator = new MaxnoMgr();
    private Map m_maxNoList = new Hashtable(10);
    private static final int POOL_SIZE = 10;

    private int getMaxNo(String noType)
    {
        MaxnoInfo maxNoInfo;
        if (m_maxNoList.containsKey(noType))
        {
            maxNoInfo = (MaxnoInfo) m_maxNoList.get(noType);
        }else
        {
            maxNoInfo = new MaxnoInfo(POOL_SIZE, noType);
            m_maxNoList.put(noType, maxNoInfo);
        }
        return maxNoInfo.getMaxNo();
    }

    public static String createMaxNo(String noType, int length)
    {
        return StringUtils.lpad(String.valueOf(generator.getMaxNo(noType.toLowerCase())), length, "0");
    }
}
